<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/16
 * Time: 10:16
 */

namespace app\manage\controller;

use think\Request;
use think\Controller;
use think\Validate;
use \app\manage\model\ContracTmanagement;
use \app\manage\model\TenantManagement;

class Lease extends Controller
{
    /**
     * 租赁显示
     */
    public function leaseLise(){
        $model=new ContracTmanagement();
        $list=$model->index();
        returnJson(200,"成功",$list)->send();die;
    }
    /**
     * 业务办理显示
     */
    public function tenantOne(){
        $model=new TenantManagement();
        $input=input();
        $id=trim( $input['information'] );
        $p=trim( $input['p'] );
        $list=$model->tenantSearch($id,$p);
        returnJson(200,"成功",$list)->send();die;
    }
    /**
     * 租赁显示
     */
    public function contractedList(){
        $model=new ContracTmanagement();
        $input=input();
        $id=trim( $input['c_id'] );
        $list=$model->T_One($id);
        returnJson(200,"成功",$list)->send();die;
    }
    /**
     * 办理入住显示
     */
    public function checkIn(){
        $model=new ContracTmanagement();
        $input=input();
        $id=trim( $input['c_id'] );
        $list=$model->check_In($id);
       // var_dump($list);exit;
        returnJson(200,"成功",$list)->send();die;
    }

    /**
     * 添加入住者
     */
   public function contractedHousing(){
        $model=new ContracTmanagement();
        $input=input();
       if(Request::instance()->isGet()){
           $id=trim( $input['c_h_id'] );
         //  $c_room=trim( $input['c_room'] );//房源类型
           $list=$model->s_housing($id);
           returnJson(200,"成功",$list)->send();die;
       }else{
           //添加入住者
           $validate = new Validate([
               ['resident_name', 'require', '姓名不能为空'],
               ['resident_front', 'require', '身份证正面不能为空'],
               ['resident_sex', 'require', '性别不能为空'],
               ['resident_back', 'require', '身份证反面不能为空'],
               ['resident_famous_race', 'require', '名族不能为空'],
               ['resident_address', 'require', '地址不能为空']
           ]);
           if(!$validate->check($input))
           {
               returnJson(-1001,  $validate->getError())->send();die;
           }
           $date=$model->contracte_housing($input);
           if($date){
               returnJson(200,"成功",$date)->send();die;
           }else{
               returnJson(-412,"用户重复")->send();die;
           }
       }
    }
    /**
     * 删除入住者
     */
    public function contractedDel(){
        $model=new ContracTmanagement();
        $input=input();
        $id=trim( $input['resident_id'] );
        $date=$model->contracted_del($id);
        if($date){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-412,"失败")->send();die;
        }

    }

    /**
     * 添加交接物品
     */
    public function handoverItemsAdd(){
        $model=new ContracTmanagement();
        $input=input();
        //添加入住者
        $validate = new Validate([
            ['h_i_name', 'require', '物品名不能为空'],
            ['number', 'require', '数量不能为空']
        ]);
        if(!$validate->check($input))
        {
            returnJson(-1001,  $validate->getError())->send();die;
        }
        $date=$model->itemsAdd($input);
        if($date){
            returnJson(200,"成功",$date)->send();die;
        }else{
            returnJson(-412,"添加失败")->send();die;
        }
    }
    /**
     * 删除交接物品
     */
    public function handoverItemsDel(){
        $model=new ContracTmanagement();
        $input=input();
        $id=trim( $input['h_i_id'] );
        $date=$model->itemsDel($id);
        if($date){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-412,"失败")->send();die;
        }
    }
    /**
     * 住房和商铺多个和单个显示
     */
    public function housingList(){
        $model=new ContracTmanagement();
        $input=input();
        $cid=trim( $input['c_id'] );//合同id
        $c_room=trim( $input['c_room'] );//房源类型
        $list=$model->s_housing($cid,$c_room);
        if($list){
            returnJson(200,"成功",$list)->send();die;
        }else{
            returnJson(-412,"失败")->send();die;
        }
    }
    /**
     * 多个住房商铺或者房源点击入住显示入住信息
     */
    public function CheckInInformation(){
        $model=new ContracTmanagement();
        $input=input();
        $c_id=trim( $input['c_id'] );//合同id
        $cid=trim( $input['c_h_id'] );//房源合同关联id
        $c_room=trim( $input['c_room'] );//房源类型
        $list=$model->CheckIn($cid,$c_room,$c_id);
        if($list){
            returnJson(200,"成功",$list)->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 点击保存和办理完成
     */
    public function housingPreservation(){
        $model=new ContracTmanagement();
        $input=input();
        $list=$model->housingPreservationAdd($input);
        if($list){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 多房源点击保存和办理完成
     */
    public function contractCompletion(){
        $model=new ContracTmanagement();
        $input=input();
        $list=$model->contractCompletion($input);
        if($list){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 租赁查看
     */
    public function leaseInformation(){
        $model=new ContracTmanagement();
        $input=input();
        $c_id=trim( $input['c_id'] );//合同id
        $list=$model->Lease_information($c_id);
        if($list){
            returnJson(200,"成功",$list)->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 租赁多个房源点击单个查看
     */
    public function housingInformation(){
        $model=new ContracTmanagement();
        $input=input();
        $c_h_id=trim( $input['c_h_id'] );//合同房源关联id
        $c_room=trim( $input['c_room'] );//房源类型
        $list=$model->housingItems($c_h_id,$c_room);
        if($list){
            returnJson(200,"成功",$list)->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 点击退租单房源和多房源显示
     */
    public function rentWithdrawalList(){
        $model=new ContracTmanagement();
        $input=input();
        $c_h_id=trim( $input['c_id'] );//合同id
        $list=$model->rentWithdrawal($c_h_id);
        if($list){
            returnJson(200,"成功",$list)->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 多房源显示点击其中一个房源显示物品
     */
    public function housingItmes(){
        $model=new ContracTmanagement();
        $input=input();
        $c_h_id=trim( $input['c_h_id'] );//合同房源关联id
        $list=$model->housingItmes($c_h_id);
        if($list){
            returnJson(200,"成功",$list)->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 多房源显示点击其中一个房源显示物品
     */
    public function itmesExamine(){
        $model=new ContracTmanagement();
        $input=input();
        $list=$model->itmesExamine($input);
        if($list){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 取消退房
     */
    public function CancellationCheckOut(){
        $model=new ContracTmanagement();
        $input=input();
        $c_id=trim( $input['c_id'] );//合同id
        $list=$model->CancellationCheckOut($c_id);
        if($list){
            returnJson(200,"成功",$list)->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 提交退租显示
     */
    public function SubmitRentRebate(){
        $model=new ContracTmanagement();
        if(Request::instance()->isGet()){
            $input=input();
            $c_id=trim( $input['c_id'] );//合同id
            $list=$model->SubmitRentRebate($c_id);
            if($list){
                returnJson(200,"成功",$list)->send();die;
            }else{
                returnJson(-413,"失败")->send();die;
            }
        }else{
            $input=input();
            $date=$model->SubmitRentRebateAdd($input);
            if($date){
                returnJson(200,"成功")->send();die;
            }else{
                returnJson(-412,"添加失败")->send();die;
            }
        }
    }
    /**
     * 退租完成点击
     */
    public function rentRefundCompleted(){
        $model=new ContracTmanagement();
        $input=input();
        $c_id=trim( $input['c_id'] );//合同id
        $list=$model->rentRefundCompleted($c_id);
        if($list){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }
    /**
     * 查看核查信息
     */
    public function checkInformation(){
        $model=new ContracTmanagement();
        $input=input();
        $c_h_id=trim( $input['c_h_id'] );//合同房源关联id
        $list=$model->checkInformation($c_h_id);
        if($list){
            returnJson(200,"成功",$list)->send();die;
        }else{
            returnJson(-413,"失败")->send();die;
        }
    }

    /**
     * 预约看房列表
     */
    public function orderHouse(){
        $model=new ContracTmanagement();
        $input=input();
        $list=$model->orderHouse($input);
        returnJson(200,"成功",$list)->send();die;

    }
    /**
     * 预约看房确认
     */
    public function reservationConfirmation(){
        $model=new ContracTmanagement();
        $input=input();
        $list=$model->reservationConfirmation($input);
        if($list){
            returnJson(200,"成功")->send();die;
        }else{
            returnJson(-432,"失败")->send();die;
        }
    }
    /**
     * 用户查找
     */
    public function userTel(){
        $model=new ContracTmanagement();
        $input=input();
        $list=$model->user_tel($input);
        returnJson(200,"成功",$list)->send();die;
    }
    /**
     * 用户查找
     */
    public function cs(){
        /* $QiNiu=config('QiNiu')['ACCESSKEY'];
        var_dump($QiNiu);exit;
       $model=new ContracTmanagement();
        $input=input();
        $list=$model->user_tel($input['tel']);
        returnJson(200,"成功",$list)->send();die;*/
    }
}